package com.example.websocket;
import websocket.notify_node;
import websocket.websocket_adapter;
import websocket.ws_ans;
import de.tavendo.autobahn.WebSocketConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.support.v4.app.NavUtils;

public class MainActivity extends Activity 
{
	WebSocketConnection wsc;
	Button m_btn_test = null;
	private static final int MSG_LOGIN_RES = 0x11;
	
	private Handler m_handler = new Handler()
	{
        @Override
        public void handleMessage(Message msg) 
        {
        	switch(msg.what)
        	{
	        	case MSG_LOGIN_RES:
	        	{
	        		ws_ans login_res = (ws_ans)msg.obj;
	        		Log.e("main",login_res.m_result.statusCode);
	        	}break;
        	}
        }
	};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        m_btn_test = (Button)this.findViewById(R.id.btn_test);
        m_btn_test.setOnClickListener
        (
        	new OnClickListener()
        	{
				@Override
				public void onClick(View arg0) 
				{
					websocket_adapter ws = websocket_adapter.getInstance(MainActivity.this);
			    	ws.connect("ifqqfi@gmail.com","123321",new notify_node(MSG_LOGIN_RES,m_handler));
				}
        	}
        );
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
        
    }
    @Override
    public void onResume()
    {
    	super.onResume();
    }

}
